import xbmc,xbmcaddon,xbmcgui,sys
from notification_service import NotificationService


_settings = xbmcaddon.Addon(id='script.follwit')
_language = _settings.getLocalizedString
if _settings.getSetting('debug') == 'true':
    debug = True
else:
    debug = False
notify = NotificationService(debug)
notify.events.follwitAddon.verifySettings()
if not notify.events.follwitAddon.follwitAPI.authUser():
    xbmcgui.Dialog().ok("Follw.it Service", _language(2102).encode( "utf-8", "ignore" )) # incorrect Username or Password
    notify.events.follwitAPI.close()
    sys.exit()

if _settings.getSetting('syncmovies') == 'true' or _settings.getSetting('syncepisodes') == 'true':
    if _settings.getSetting('syncmovies') == 'true':
        _settings.setSetting('syncmovies', 'false')
        notify.events.follwitAddon.syncMovies()
    if _settings.getSetting('syncepisodes') == 'true':
        _settings.setSetting('syncepisodes', 'false')
        notify.events.follwitAddon.syncEpisodes()
    xbmcgui.Dialog().ok("Follw.it Service", _language(2106).encode( "utf-8", "ignore" )) # restart xbmc to reset sync flags
notify.run()
notify.events.follwitAddon.follwitAPI.close()